package game.io;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;

import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;

public class ImageLoader {

	public BufferedImage loadImage(String fnm)
	// load the image from images/fnm
	{
		BufferedImage im = null;
		try {
			im = ImageIO.read(getClass().getResource("images/" + fnm));
		} catch (IOException e) {
			System.out.println("Could not load image from images/" + fnm);
		}
		return im;
	} // end of loadImage()

	public Texture loadTexture(String fnm) {
		String fileName = "images/" + fnm;
		Texture tex = null;
		try {
			tex = TextureIO.newTexture(new File(fileName), false);
			tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
			tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
		} catch (Exception e) {
			System.out.println("Error loading texture " + fileName);
		}

		return tex;
	} // end of loadTexture()

}
